package com.chb.controller;

import com.chb.annotation.LogAnnotation;
import com.chb.model.entity.Staff;
import com.chb.model.vo.Result;
import com.chb.model.vo.StaffVo;
import com.chb.service.StaffService;
import com.chb.utils.PagingUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author: 陈海彬
 * @date: Created in 2023/9/25 19:08
 * @description: 用户信息控制层
 * @modified By:
 * @version: 1.0
 */
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    private StaffService staffService;
    @Autowired
    private HttpSession session;

    /**
     * @create by: 陈海彬
     * @description: 获取用户信息
     * @create time: 2023/9/25 19:09
     */
    @GetMapping("/info1")
    public Result info1() {
        Staff staff = (Staff) session.getAttribute("staff");
        return Result.success(staff);
    }

    /**
     * @param session 用户登录的session
     * @create by: 陈海彬
     * @description: 获取用户信息
     * @create time: 2023/9/25 19:09
     */
    @GetMapping("/info")
    public Result info(HttpSession session) {
        Staff staff = (Staff) session.getAttribute("staff");
        return Result.success(staff);
    }

    @RequestMapping("/staffInfo")
    public Result staffInfo(Integer current, Integer pageSize, @RequestBody StaffVo staffVo) {
        Result result = staffService.findAllStaffInfo(current, pageSize, staffVo);
        return result;
    }

    /**
     * @return com.chb.model.vo.Result
     * @create by: 张77
     * @description: 获取所有部门名称信息
     * @create time: 2023/10/7 11:04
     */
    @RequestMapping("/getDeptment")
    public Result getDeptment() {
        return staffService.getDeptment();
    }
    /**
    * @create by: 张77
    * @description:新增下拉框获取部门
    * @create time: 2023/10/12 20:03
     * @param
    * @return
     */
    @RequestMapping("/getDeptmentNew")
    public Result getDeptmentNew() {
        return staffService.addfendAllDept();
    }

    /**
     * @param
     * @return
     * @create by: 张77
     * @description:获取所有状态信息
     * @create time: 2023/10/8 15:40
     */
    @RequestMapping("/getState")
    public Result getState() {
        return staffService.getState();

    }

    /**
     * @param staff 员工信息
     * @return com.chb.model.vo.Result
     * @create by: 张77
     * @description: 修改员工信息
     * @create time: 2023/10/7 17:11
     */
    @PostMapping("/updateStaff")
    @LogAnnotation(business_type = "修改员工信息")
    public Result updateStaff(@RequestBody Staff staff) {
        return staffService.updateStaff(staff);
    }

    /**
     * @param staffid 用户id
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 判断该用户是否可以被平调
     * @create time: 2023/10/12 10:34
     */
    @GetMapping("/transferJudgment")
    public Result transferJudgment(Integer staffid) {
        return staffService.transferJudgment(staffid);
    }

    /**
     * @param staff
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 确认调离
     * @create time: 2023/10/12 10:54
     */
    @PostMapping("/transferConfirmed")
    public Result transferConfirmed(@RequestBody Staff staff) {
        return staffService.transferConfirmed(staff);
    }

    /**
     * @param phone 手机号
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 校验手机号是否重复
     * @create time: 2023/10/12 12:26
     */
    @GetMapping("/phoneIsReplace")
    public Result phoneIsReplace(String phone,Integer staffid) {
        return staffService.phoneIsReplace(phone,staffid);
    }

    /**
     * @param staffid
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 判断用户名是否重复
     * @create time: 2023/10/12 14:49
     */
    @GetMapping("/staffidIsReplace")
    public Result staffidIsReplace(Integer staffid) {
        return staffService.staffidIsReplace(staffid);
    }


    /**
     * @param idCar
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 判断身份证是否重复
     * @create time: 2023/10/12 14:55
     */
    @GetMapping("/checkIdCar")
    public Result checkIdCar(String idCar) {
        return staffService.checkIdCar(idCar);
    }

    /**
     * @param staff
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 添加员工
     * @create time: 2023/10/12 15:00
     */
    @PostMapping("/addStaff")
    public Result addStaff(@RequestBody Staff staff) {
        return staffService.addStaff(staff);
    }
    /**
    * @create by: 张77
    * @description:添加框的职位信息
    * @create time: 2023/10/12 20:42
     * @param
    * @return
     */
    @GetMapping("/info2")
    public Result info2() {
        Result result = staffService.addfendAllRole();
        return result;
    }
}